<?php
/**
 * Created by PhpStorm.
 * 楼小二地标
 * User: caicm
 * Date: 2017/2/18
 * Time: 9:22
 */

namespace SDXApi\Model;
use Think\Model;


class LouxiaoerLandmarkModel extends Model
{
    /*
     * 添加地标
     * Created By caicm
     * @param string $name 地标名称
     * @param int $region_id 区域id
     * return bool
     *
     */
    public function addLandmark($name, $region_id, $wdtype=0){

        $data = array(
            'name' => $name,
            'region_id' => $region_id,
            'add_time' => gmtime()
        );

        return $this->add($data);

    }

    /*
     * 获取地标
     * Created By caicm
     * @param string $name 地标名称
     * @param int $region_id 地标id
     * return bool
     */
    public function findLandmarkByName($name, $region_id){

        $where = array(
            'name' => $name,
            'region_id' => $region_id
        );

        return $this->where($where)->find();

    }

    /*
     * 根据地标、区域查询楼小二
     * Created By caicm
     * @param string $name 地标名称
     * @param int $wdr_id 区域id
     * return mixed
     */
    public function findLouxiaoerByLandmark($name, $wdr_id){

        $where = array(
            'l.name' => $name,
            'l.region_id' => $wdr_id
        );

        $field = "l.id,l.louxiaoer_id,w.name,a.user_name as phone";

        return   $this->alias('l')
            ->field($field)
            ->join("left join sdx_warehouse_personnel as w on l.louxiaoer_id=w.uid")
            ->join("left join sdx_admin_user as a on l.louxiaoer_id=a.user_id")
            ->where($where)
            ->find();

    }
}